#region [file: AgenciaDAL.cs, author: Lucas Bittencourt]
// File:    AgenciaDAL.cs
// Author:  Lucas Bittencourt
// Created: segunda-feira, 7 de novembro de 2011 20:48:48
// Purpose: Defines dao implementation class for class Agencia
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IAgenciaDAL interface
   /// </summary>
   public class AgenciaDAL : NHibernateDALBase,  IAgenciaDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Agencia
      /// </summary>     
      public List<Agencia> GetAgenciaList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Agencia)));
      }
      
      /// <summary>
      /// Get the instances of Agencia from index firstResult to index maxResult
      /// </summary>
      public List<Agencia> GetAgenciaList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Agencia), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Agencia according its primary key instance.
      /// </summary>
      public Agencia Load(AgenciaPK agenciaPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "AgcIdAgencia" };
         object[] values = new object[] { agenciaPK.AgcIdAgencia };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Agencia), cs);
         return (((list != null) && (list.Count > 0)) ? (Agencia)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Agencia according its example instance.
      /// </summary>
      public List<Agencia> QueryByExample(Agencia agencia)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Agencia), agencia));
      }

      /// <summary>
      /// Query the instances of Agencia according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Agencia> QueryByExample(Agencia agencia, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Agencia), agencia, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Agencia
      /// </summary>
      public void Insert(Agencia agenciaObject)
      {
         base.Save(agenciaObject);
      }
      
      /// <summary>
      /// Update the instances of Agencia
      /// </summary>
      public void Update(Agencia agenciaObject)
      {
         base.Update(agenciaObject);
      }
      
      /// <summary>
      /// Delete the instances of Agencia
      /// </summary>
      public void Delete(Agencia agenciaObject)
      {
         base.Delete(agenciaObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNuAgencia
      /// </summary>
      public List<Agencia> FindByAgcNuAgencia(string agcNuAgencia) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNuAgencia", agcNuAgencia));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs));
      }
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNuAgencia, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Agencia> FindByAgcNuAgencia(string agcNuAgencia, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNuAgencia", agcNuAgencia));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNuDigitoAgencia
      /// </summary>
      public List<Agencia> FindByAgcNuDigitoAgencia(string agcNuDigitoAgencia) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNuDigitoAgencia", agcNuDigitoAgencia));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs));
      }
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNuDigitoAgencia, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Agencia> FindByAgcNuDigitoAgencia(string agcNuDigitoAgencia, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNuDigitoAgencia", agcNuDigitoAgencia));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNmAgencia
      /// </summary>
      public List<Agencia> FindByAgcNmAgencia(string agcNmAgencia) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNmAgencia", agcNmAgencia));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs));
      }
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNmAgencia, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Agencia> FindByAgcNmAgencia(string agcNmAgencia, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNmAgencia", agcNmAgencia));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNuCnpj
      /// </summary>
      public List<Agencia> FindByAgcNuCnpj(string agcNuCnpj) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNuCnpj", agcNuCnpj));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs));
      }
      
      /// <summary>
      /// Find the instances of Agencia according to its attribute agcNuCnpj, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Agencia> FindByAgcNuCnpj(string agcNuCnpj, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("AgcNuCnpj", agcNuCnpj));
         return ConvertToGenericList(base.FindByCriterions(typeof(Agencia), cs, firstResult, maxResult));
      }
      
      /// <summary>
      /// Find <Code>Agencia</Code> instances by Banco
      /// </summary>
      /// <param name="banco"/>
      /// <returns>Agencia instance list</returns>
      public List<Agencia> FindByBanco(Banco banco)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Banco", banco));
         return ConvertToGenericList(base.FindByCriterions(typeof(Banco), cs));
      }
      
      /// <summary>
      /// Find <Code>Agencia</Code> instances  instances in range firstResult, maxResult by Banco
      /// </summary>
      /// <param name="banco"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Agencia instance list</returns>
      public List<Agencia> FindByBanco(Banco banco, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Banco", banco));
         return ConvertToGenericList(base.FindByCriterions(typeof(Banco), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Agencia> ConvertToGenericList(IList agencias)
      {
         List<Agencia> agenciaList = new List<Agencia>();
         foreach (Agencia agencia in agencias)
         {
             agenciaList.Add(agencia);
         }
         return agenciaList;
      }      
   }
}